package licode.unisop.log.client.feign.impl;

import licode.unisop.client.api.auth.AuthTokenShim;
import licode.unisop.log.client.api.AuditLogApi;
import licode.unisop.log.client.dto.AuditLogDTO;
import licode.unisop.log.client.feign.LogOpFeign;
import licode.unisop.log.client.feign.LogQueryFeign;
import licode.unisop.log.client.req.AuditLogIn;
import licode.unisop.unilite.dp.PageData;
import licode.unisop.unilite.utils.TryMethodCall;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class AuditLogApiFeign implements AuditLogApi {
    @Resource
    private LogQueryFeign logQueryFeign;

    @Resource
    private LogOpFeign logOpFeign;

    @Resource
    private AuthTokenShim authTokenShim;

    @Override
    public void save(AuditLogDTO auditLogDto) {
        logOpFeign.saveAudit(authTokenShim.platformToken(""), auditLogDto);
    }

    @Override
    public void saveList(List<AuditLogDTO> auditLogs) {

    }

    @Override
    public PageData<AuditLogDTO> query(AuditLogIn auditLogIn) {
        return TryMethodCall.execFeign(()->
                logQueryFeign.auditList(authTokenShim.platformToken(""), auditLogIn));
    }
}
